package com.example;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;

public class Main {

    public static void main(String[] args) {
        List<String> dateStrings = new ArrayList<>();
        dateStrings.add("2024-07-31");
        dateStrings.add("2024-08-01");

        // 转换日期字符串为LocalDate对象列表
        List<LocalDate> dates = new ArrayList<>();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        for (String dateString : dateStrings) {
            LocalDate date = LocalDate.parse(dateString, formatter);
            dates.add(date);
        }

        // 排序日期对象列表
        dates.sort(LocalDate::compareTo);

        // 计算连续次数
        int consecutiveCount = 1;
        int maxConsecutiveCount = 1;

        for (int i = 1; i < dates.size(); i++) {
            // 检查是否连续
            if (dates.get(i).minusDays(1).equals(dates.get(i - 1))) {
                consecutiveCount++;
            } else {
                // 更新最大连续次数并重置连续计数器
                if (consecutiveCount > maxConsecutiveCount) {
                    maxConsecutiveCount = consecutiveCount;
                }
                consecutiveCount = 1;
            }
        }

        // 最后检查一次，因为可能在最后几天是连续的
        if (consecutiveCount > maxConsecutiveCount) {
            maxConsecutiveCount = consecutiveCount;
        }

        System.out.println("最大连续次数: " + maxConsecutiveCount);
    }
}
